/**
 * 滚动条重复事件
 * 详细请参考eventBus中的事件介绍
 * @param refValue refs的名称拿到dom
 * @returns {{methods: {handleSetMainScroll(*): void, handleMainScroll(): void}, beforeDestroy(): void, mounted(): void}}
 */
export default function (refValue) {
  return {
    mounted () {
      this.$bus.$on('setMainScroll', this.handleSetMainScroll)
      this.$refs[refValue].addEventListener('scroll', this.handleMainScroll)
    },
    beforeDestroy () {
      this.$bus.$emit('mainScroll')
      this.$bus.$off('setMainScroll', this.handleSetMainScroll)
      this.$refs[refValue].removeEventListener('scroll', this.handleMainScroll)
    },
    methods: {
      handleSetMainScroll (scrollTop) {
        this.$refs[refValue].scrollTop = scrollTop
      },
      handleMainScroll () {
        this.$bus.$emit('mainScroll', this.$refs[refValue])
      }
    }
  }
}
